package com.cloudcc.mobile.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import com.cloudcc.cloudframe.util.NearByUtil;
import com.cloudcc.mobile.R;

/**
 * @author wangzhiqiang
 * @Description: 系统相关 比如打电话等
 * @date 2015-11-25 下午1:54:58
 */
public class SystemUtils {

    /**
     * 打电话
     *
     * @param context
     * @param mobileNumber
     */
    public static void sendCall(Context context, String mobileNumber) {
        String tel = "tel:" + mobileNumber;
        Uri uri = Uri.parse(tel);
        Intent intent = new Intent(Intent.ACTION_CALL, uri);
        context.startActivity(intent);
    }

    /**
     * 发送短信
     *
     * @param context
     * @param mobileNumber
     */
    public static void sendSms(Context context, String mobileNumber) {
        Uri smsToUri = Uri.parse("smsto:");
        Intent sendIntent = new Intent(Intent.ACTION_VIEW, smsToUri);
        sendIntent.putExtra("address", mobileNumber); // 电话号码，这行去掉的话，默认就没有电话
        sendIntent.setType("vnd.android-dir/mms-sms");
        context.startActivity(sendIntent);
    }

    /**
     * 发邮件
     *
     * @param context
     * @param emailAddress
     */
    public static void sendEmail(Context context, String emailAddress) {
        Uri smsToUri = Uri.parse("mailto:" + emailAddress);
        Intent sendIntent = new Intent(Intent.ACTION_SENDTO, smsToUri);
        context.startActivity(sendIntent);
    }


    /**
     * DP转换px
     *
     * @param dp
     * @param mcontext
     * @return
     */
    public static float dpToPx(float dp, Context mcontext) {
        return dp * mcontext.getResources().getDisplayMetrics().density;
    }

    /**
     * 打开地图显示地址位置
     *
     * @param context
     * @param latitude
     * @param longitude
     * @param zoneName
     */
    public static void sendMap(Context context, float latitude, float longitude, String zoneName) {
        try {
            Uri mUri = Uri.parse("geo:" + latitude + "," + longitude + "?q=" + zoneName);
            Intent mIntent = new Intent(Intent.ACTION_VIEW, mUri);
            context.startActivity(mIntent);
        } catch (Exception e) {
            // TODO: handle exception
            Tools.showInfo(context,context.getString(R.string.gaodemaptoast));
        }

    }

    /**
     * 用默认浏览器打开指定的URL
     *
     * @param context
     * @param url
     */
    public static void startUrl(Context context, String url) {
        if (!url.startsWith("http:\\")) {
            url = "http:\\" + url;
        }
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        context.startActivity(intent);
    }
}
